/**
 * @format
 * @Author: TC
 * @Date: 2025-07-28 16:50:21
 * @Last Modified by: TC (tengchao@taqu.cn)
 * @Last Modified time: 2025-10-17 16:46:50
 */

import { _decorator, Component, easing, Node, tween, v3 } from "cc";
import { app } from "db://assets/FrameWork/App";
import { BaseUI } from "db://assets/FrameWork/Module/Component/BaseUI";
import { gameMole } from "../../../GameMole";
import { MoleHole } from "../Item/MoleHole";
import { MoleHpUI } from "./MoleHpUI";
const { ccclass, property } = _decorator;

/**
 * 战斗界面
 */
@ccclass("MoleBattleUI")
export class MoleBattleUI extends BaseUI {
    @property({ type: Node, displayName: "暂停按钮" })
    private btnPause: Node = null;
    @property({ type: Node, displayName: "洞窟层" })
    private layerHole: Node = null;
    @property({ type: MoleHpUI, displayName: "血条" })
    private hpPanel: MoleHpUI = null;

    protected init(): void {
        super.init();
    }

    protected addUIEvent(): void {
        super.addUIEvent();
        this.addClickEvent(this.btnPause, this._onPause);
    }

    protected onShow(): void {
        super.onShow();
        this.hpPanel.initUI();
        this._initHoleList();
        this._starBattle();
    }

    /**
     * 初始化鼠洞列表
     */
    private _initHoleList(): void {
        gameMole.battleMgr.layerHole = this.layerHole;
        for (let i = 0; i < 9; i++) {
            const hole = this.layerHole.getChildByName("" + i).getComponent(MoleHole);
            gameMole.battleMgr.addHole(hole);
        }
    }

    private _starBattle(): void {
        gameMole.battleMgr.startBattle();
    }

    /**
     * 点击暂停
     */
    private _onPause(): void {
        gameMole.battleMgr.pause();
    }

    /**
     * 点击退出
     */
    private _onExit(): void {
        // gameMole.battleMgr.endBattle();
        gameMole.battleMgr.release();
        this.closeUI();
    }
}
